package com.honghe.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.honghe.common.annotation.Log;
import com.honghe.common.core.controller.BaseController;
import com.honghe.common.core.domain.AjaxResult;
import com.honghe.common.enums.BusinessType;
import com.honghe.system.domain.ContactRecordLog;
import com.honghe.system.service.IContactRecordLogService;
import com.honghe.common.utils.poi.ExcelUtil;
import com.honghe.common.core.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.honghe.common.utils.SecurityUtils;

/**
 * 客户联系记录日志Controller
 * 
 * @author honghe
 */
@RestController
@RequestMapping("/system/contactlog")
public class ContactRecordLogController extends BaseController
{
    private static final Logger logger = LoggerFactory.getLogger(ContactRecordLogController.class);

    @Autowired
    private IContactRecordLogService contactRecordLogService;

    /**
     * 查询客户联系记录日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:contactlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContactRecordLog contactRecordLog)
    {
        startPage();
        List<ContactRecordLog> list = contactRecordLogService.selectContactRecordLogList(contactRecordLog);
        return getDataTable(list);
    }

    /**
     * 根据客户ID查询联系记录日志
     */
    @PreAuthorize("@ss.hasPermi('system:contactlog:list')")
    @GetMapping("/listByCaseId/{caseId}")
    public AjaxResult listByCaseId(@PathVariable("caseId") String caseId)
    {
        logger.info("根据客户ID查询联系记录日志列表, 客户ID: {}", caseId);
        try {
            List<ContactRecordLog> list = contactRecordLogService.selectContactRecordLogByCaseId(caseId);
            return success(list);
        } catch (Exception e) {
            logger.error("查询联系记录日志失败: ", e);
            return error("查询联系记录日志失败: " + e.getMessage());
        }
    }

    /**
     * 根据记录ID查询联系记录日志
     */
    @PreAuthorize("@ss.hasPermi('system:contactlog:list')")
    @GetMapping("/listByRecordId/{recordId}")
    public AjaxResult listByRecordId(@PathVariable("recordId") Long recordId)
    {
        logger.info("根据记录ID查询联系记录日志列表, 记录ID: {}", recordId);
        try {
            List<ContactRecordLog> list = contactRecordLogService.selectContactRecordLogByRecordId(recordId);
            return success(list);
        } catch (Exception e) {
            logger.error("查询联系记录日志失败: ", e);
            return error("查询联系记录日志失败: " + e.getMessage());
        }
    }

    /**
     * 导出客户联系记录日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:contactlog:export')")
    @Log(title = "客户联系记录日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ContactRecordLog contactRecordLog)
    {
        List<ContactRecordLog> list = contactRecordLogService.selectContactRecordLogList(contactRecordLog);
        ExcelUtil<ContactRecordLog> util = new ExcelUtil<ContactRecordLog>(ContactRecordLog.class);
        return util.exportExcel(list, "客户联系记录日志");
    }

    /**
     * 获取客户联系记录日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contactlog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(contactRecordLogService.selectContactRecordLogById(logId));
    }

    /**
     * 删除客户联系记录日志
     */
    @PreAuthorize("@ss.hasPermi('system:contactlog:remove')")
    @Log(title = "客户联系记录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(contactRecordLogService.deleteContactRecordLogByIds(logIds));
    }
} 